<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
<title>附件管理</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<link href="/resources/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script src="/resources/lib/jquery/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="/resources/lib/ligerUI/js/ligerui.all.js" type="text/javascript"></script>
<script type="text/javascript">
	var $grid;
	$(function (){
            $("form").ligerForm();
			 $grid = $("#maingrid").ligerGrid({
	                columns: [
	                	{ name: 'uuid', hide:true,type:"text"},
	                    { display: '附件名称', name: 'serverFileName', width: 100,type:"text"},
	                    { display: '大小', name: 'fileSize', width: 100,type:"text"},
	                    { display: '上传时间', name: 'onLoadDate', width: 100,type:"text"},
			 		],
	                width: '100%', height: '100%',
	                checkbox: true,headerRowHeight:22, rowHeight:22, rownumbers:true,
	                url:'/formFile/queryFormFile?resourceId=${resourceId}',
			 		 toolbar: { items: [
		                                   { text: '下载', click: downClick, icon: 'down' },
		                                   { line: true },
		                                   { text: '删除', click: removeClick, icon: 'remove' },
			 		 ]}
			 });
        }); 
</script>
</head>
<body>
	<form id="form1" action="/formFile/fileUpload?resourceId=${resourceId}" method="post" encType="multipart/form-data">
		<table>
			<tr>
				<td><input name="files" type="file" style="width:240px;margin-left:0px;margin-top:0px;height:24px;position:absolute;opacity:0;filter:alpha(opacity=0);z-index:999"  
					 			onchange="this.form.inputs.value=this.value.substr(this.value.lastIndexOf('\\')+1);"/>
					<input name="inputs" type="text" style="width:200px; height:16px;z-index:999" disabled="disabled" />
				</td>
				<td><input type="button" class="l-button" value="浏览"/></td>
				<td><input type="submit" value="上传" class="l-button"/></td>
			</tr>
		</table>
	</form>
	<div id="maingrid"></div> 
</body>
<script type="text/javascript">
	//下载
	function downClick(){
		var rows = $grid.getSelectedRows();
    	if(rows.length != 1){
    		$.ligerDialog.error("一次只能下载一个附件");
    		return;
    	}
    	console.log(rows);
		document.location = "/formFile/fileDownload?resourceId=" + rows[0].uuid;
	}
	
	//删除
	function removeClick(){
		var rows = $grid.getSelectedRows();
    	if(rows.length != 1){
    		$.ligerDialog.error("一次只能下载一个附件");
    		return;
    	}
		$.ajax({
			url:"/formFile/fileDel",
			data:{resourceId: rows[0].uuid},
			type: "post", 
			dataType:'json',
			success: function(data){
				$.ligerDialog.success(data.message,'信息',function(){
		        	 $grid.reload();
				});
			},
	        error: function (message) {
	            $.ligerDialog.error("删除失败");
	        }
		});
	}
</script>
</html>